package com.hq.fxh.No3_TuiGuang.MyMoBan.Activity;


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;


import com.hq.fxh.HttpApi.UserServiceImpl;
import com.hq.fxh.Intefers.NetworkSubscriber;
import com.hq.fxh.No0_ChengQu.Fragment.BaseFragment;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item.ToastUtils;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.GetAdvertByUidRes;
import com.hq.fxh.R;
import com.hq.fxh.Utils.SharedPreferenceUtils;

import java.util.ArrayList;
import java.util.List;




public class BigBannnerTempFragment extends BaseFragment {
    private RecyclerView recyclerView;
    private int uid;
    List<AdBannerInfo> currentData = new ArrayList<>();
    public BigBusinessAdAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_big_bannner_temp;
    }

    @Override
    protected void findView(View view) {
        recyclerView =(RecyclerView)view.findViewById(R.id.recyclerView);
    }

    @Override
    protected void initData() {
        uid = SharedPreferenceUtils.getMemberId(getActivity());
        RecyclerView.LayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(manager);

        UserServiceImpl.getEnterpriseAdvert(uid + "", new NetworkSubscriber<GetAdvertByUidRes>() {
            @Override
            public int onSuccess(GetAdvertByUidRes data) {
                super.onSuccess(data);
                if (data != null && data.getCode() == 0) {
                    currentData.clear();
                    currentData.addAll(data.getData().getBigPic());
                    if (adapter == null) {
                        adapter = new BigBusinessAdAdapter(getActivity(), currentData);
                        recyclerView.setAdapter(adapter);
                    } else {
                        adapter.notifyDataSetChanged();
                    }
                } else {
                    ToastUtils.show(getActivity(), data.getMsg());
                }
                return 0;
            }
        });
    }
}
